package com.wangbo.basic;

/**
 * 稀疏数组
 */
public class Client {
/* 结果
原矩阵：
0	0	7	0	0	0	0	0	0	0	0
0	0	0	-2	0	0	0	0	0	0	0
0	0	0	0	-3	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
稀疏数组：
11	11	3
0	2	7
1	3	-2
2	4	-3
新矩阵：
0	0	7	0	0	0	0	0	0	0	0
0	0	0	-2	0	0	0	0	0	0	0
0	0	0	0	-3	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0	0	0	0
 */
    public static void main(String[] args) {
        int[][] matrix = new int[11][11];
        matrix[0][2] = 7;
        matrix[1][3] = -2;
        matrix[2][4] = -3;

        System.out.println("原矩阵：");
        for (int[] row : matrix) {
            for (int item : row) {
                System.out.printf("%d\t",item);
            }
            System.out.println();
        }

        int[][] sparseArray = SparseArrayUtil.toSparseArray(matrix);
        System.out.println("稀疏数组：");
        for (int[] row : sparseArray) {
            System.out.printf("%d\t%d\t%d\n",row[0],row[1],row[2]);
        }

        int[][] newMatrix = SparseArrayUtil.toMatrix(sparseArray);
        System.out.println("新矩阵：");
        for (int[] row : newMatrix) {
            for (int item : row) {
                System.out.printf("%d\t",item);
            }
            System.out.println();
        }
    }
}
